package com.icinfo.cloud.provider.punish.config.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.icinfo.cloud.provider.punish.config.enums.DiscretionRuleApplyTypeEnum;
import com.icinfo.cloud.provider.punish.config.enums.DiscretionRuleConfigTypeEnum;
import com.icinfo.cloud.provider.punish.config.enums.DiscretionRuleTypeEnum;
import com.icinfo.cloud.provider.punish.config.model.ConfigOrgRegulatoryDiscretionRule;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * 自由裁量规则配置对象
 *
 * @author Junfeng.Chen
 * @date 2024/1/31 8:36
 **/
@Data
@NoArgsConstructor
public class ConfigOrgRegulatoryDiscretionRuleVo {
    /**
     * 事项违法情形 ConfigOrgRegulatoryDiscretionRule.id
     */
    private String id;

    /**
     * 自由裁量配置id
     *
     * .id
     */
    private String discretionId;

    /**
     * 事项历史id，每次修改此id都会变化
     */
    private String ruleHisId;

    /**
     * 部门code
     */
    private String orgCode;

    /**
     * 自由裁量配置类型
     */
    private DiscretionRuleConfigTypeEnum configType;

    /**
     * 事项唯一id
     */
    private String regulatoryCatalogId;

    /**
     * 适用类型
     */
    private DiscretionRuleApplyTypeEnum applyType;

    /**
     * 违法情形（自由裁量规则）名称
     */
    private String ruleName;

    /**
     * 违法情形规则类型
     */
    private DiscretionRuleTypeEnum ruleType;

    /**
     * 金额下限
     */
    private BigDecimal lowerLimitAmount;

    /**
     * 金额上限
     */
    private BigDecimal upperLimitAmount;

    /**
     * 固定金额
     */
    private BigDecimal fixAmount;

    /**
     * 适用简易案件 0不适用 1适用
     */
    private String applySimple;

    /**
     * 适用普通案件 0不适用 1适用
     */
    private String applyNormal;

    /**
     * 档次等级
     */
    private String gradeLevel;

    /**
     * 处罚种类集合
     */
    private List<String> punishKinds;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date createTime;

    /**
     * 创建用户名称
     */
    private String createUser;

    /**
     * 修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date updateTime;

    /**
     * 修改用户名称
     */
    private String updateUser;

    /**
     * 转换为当前对象
     *
     * @param rule
     */
    public ConfigOrgRegulatoryDiscretionRuleVo(ConfigOrgRegulatoryDiscretionRule rule) {
        BeanUtil.copyProperties(rule, this);
        this.punishKinds = Collections.emptyList();
        if (StrUtil.isNotEmpty(rule.getPunishKinds())) {
            this.punishKinds = Arrays.asList(rule.getPunishKinds().split(","));
        }
        this.configType = DiscretionRuleConfigTypeEnum.getByCode(rule.getConfigType());
        this.applyType = DiscretionRuleApplyTypeEnum.getByCode(rule.getApplyType());
        this.ruleType = DiscretionRuleTypeEnum.getByCode(rule.getRuleType());
    }
}
